﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using model;
using System.Data;

namespace Dal
{
    public class AppIntroDal
    {
        public List<AppIntro> GetList()
        {
            string sql = "select top 10 ano,ename,position,number from Enterprise,Application where Application.eno=Enterprise.eno order by Application.time desc";
            DataSet ds = DbSqlHelper.Query(sql);
            List<AppIntro> appintros = new List<AppIntro>();
            AppIntro appintro;
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                appintro = new AppIntro();
                appintro.Ano = Convert.ToInt32(row["ano"]);
                appintro.Ename = row["ename"].ToString();
                appintro.Position = row["position"].ToString();
                appintro.Number = row["number"].ToString();
                appintros.Add(appintro);
            }
            return appintros;
        }
        public List<AppIntro> GetList(string sword, string kword)
        {
            StringBuilder sql = new StringBuilder("select * from Enterprise,Application where Application.eno=Enterprise.eno");
            if (string.IsNullOrEmpty(kword) == false)
                sql.Append(" and " + sword + " like '%" + kword + "%'");
            DataSet ds = DbSqlHelper.Query(sql.ToString());
            List<AppIntro> appintros = new List<AppIntro>();
            AppIntro appintro;
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                appintro = new AppIntro();
                appintro.Ano = Convert.ToInt32(row["ano"]);
                appintro.Ename = row["ename"].ToString();
                appintro.Position = row["position"].ToString();
                appintro.Place = row["place"].ToString();
                appintro.Number = row["number"].ToString();
                appintros.Add(appintro);
            }
            return appintros;
        }

            
    }
}
